package com.database.management.common;

import java.io.IOException;  

import javax.servlet.Filter;  
import javax.servlet.FilterChain;  
import javax.servlet.FilterConfig;  
import javax.servlet.ServletException;  
import javax.servlet.ServletRequest;  
import javax.servlet.ServletResponse;  
import javax.servlet.annotation.WebFilter;
  
/* 
 *  
 * 采用Filter统一处理字符集 
 */  
@WebFilter
public class CharSetEncodingFilter implements Filter {  
  
    private String encoding = "UTF-8";  
  
    @Override  
    public void doFilter(ServletRequest arg0, ServletResponse arg1,  
            FilterChain chain) throws IOException, ServletException {  
          
        //System.out.println("CharsetEncoding--->>>begin");  
        //设置字符集  
        arg0.setCharacterEncoding(encoding);  
          
        //继续执行  
        //如果还有filter，继续调，如果没有，就调jsp  
        chain.doFilter(arg0,arg1);  
        //System.out.println("CharsetEncoding--->>>end");  
    }  
  
    @Override  
    public void init(FilterConfig arg0) throws ServletException {  
          
        //System.out.println("CharsetEncoding--->>>init");  
        this.encoding=arg0.getInitParameter("encoding");  
        //System.out.println("CharsetEncoding--->>>init"+encoding);  
    }

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}  
  
}  
